package com.zzyl.controller.customer;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.QueryDeviceDataDto;
import com.zzyl.dto.UserLoginRequestDto;
import com.zzyl.service.DeviceDataService;
import com.zzyl.service.DeviceService;
import com.zzyl.service.MemberService;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.WxLoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "客户管理")
@RestController
@RequestMapping("/customer/user")
@RequiredArgsConstructor
public class CustomerUserController {
    final MemberService memberService;
    final DeviceService deviceService;
    final DeviceDataService deviceDataService;

    /**
     * C端用户登录--微信登录
     *
     * @param dto 用户登录请求Dto
     * @return {@code ResponseResult }
     * @author YiSheep
     */
    @ApiOperation("C端用户登录--微信登录")
    @PostMapping("/login")
    public ResponseResult<WxLoginVo> login(@RequestBody UserLoginRequestDto dto) {
        log.info("C端用户登录--微信登录:{}", dto);
        WxLoginVo vo = memberService.wxLogin(dto);
        return ResponseResult.success(vo);
    }
    // ================================================= 家属端数据报表展示


    /**
     * 查询指定设备的物模型运行状态
     *
     * @param request 查询设备属性状态请求
     * @return {@code ResponseResult<DevicePropertyStatusVo> }
     * @author YiSheep
     */
    @ApiOperation("查询指定设备的物模型运行状态")
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<DevicePropertyStatusVo> QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        log.info("查询指定设备的物模型运行状态:{}", request);
        DevicePropertyStatusVo devicePropertyStatusVo = deviceService.queryDevicePropertyStatus(request);
        return ResponseResult.success(devicePropertyStatusVo);
    }


    /**
     * 按日查询设备数据
     *
     * @param dto 查询设备数据dto
     * @return {@code ResponseResult<List<DeviceDataGraphVo>> }
     * @author YiSheep
     */
    @ApiOperation("按日查询设备数据")
    @GetMapping("/queryDeviceDataListByDay")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByDay(QueryDeviceDataDto dto) {
        log.info("按日查询设备数据:{}", dto);
        List<DeviceDataGraphVo> deviceDataGraphVoList = deviceDataService.queryDeviceDataListByDay(dto);
        return ResponseResult.success(deviceDataGraphVoList);
    }

    /**
     * 按周查询设备数据
     *
     * @param dto 查询设备数据dto
     * @return {@code ResponseResult<List<DeviceDataGraphVo>> }
     * @author YiSheep
     */
    @ApiOperation("按周查询设备数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(QueryDeviceDataDto dto) {
        log.info("按周查询设备数据:{}", dto);
        List<DeviceDataGraphVo> deviceDataGraphVoList = deviceDataService.queryDeviceDataListByWeek(dto);
        return ResponseResult.success(deviceDataGraphVoList);
    }
}
